package com.iwop.moto.controller;

import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.FCommonProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by Administrator on 2016/8/26.
 */
@Controller
public class FCommonProblemController extends  BaseController{
    @Autowired
    private FCommonProblemService commonProblemService;
    /**
     * 功能:客服里面的常见问题添加<br>
     * (http://192.168.1.150:8888/platform/org/info?org_name=admin)<br>
     * 参数：cid 问题id<br>
     * 参数:title 标题<br>
     * 参数:content 内容<br>
     * 参数:catagory 类别<br>
     * <p>
     *  @return {
    "message": "暂无公司充值记录",
    "result": null,
    "code": "-1"
    }
     * </p>
     */
    @RequestMapping("/api/problem/add")
    @ResponseBody
    public ResultModel insertCommonProblem(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            String cid = UUID.randomUUID().toString();
            SRModel.put("cid", cid);
            SRModel.put("status_flag","1");
            SRModel.put("status_time",new Date());
            commonProblemService.insertCommonProblem(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     * 功能:客服里面的常见问题编辑
     * 参数:cid 问题id
     * 参数:title 标题
     * 参数:content 内容
     * 参数:catagory 类别
     */
    @RequestMapping("/api/problem/edit")
    @ResponseBody
    public ResultModel upCommonProblem(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel.put("status_time",new Date());
            commonProblemService.upCommonProblem(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     * 功能:获取问题
     * */
    @RequestMapping(value = "/api/problem/get",method = RequestMethod.GET)
    @ResponseBody
    public ResultModel getCommonProblem(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            List list=commonProblemService.getCommonProblem(SRModel);
            return getSucceed(list,ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     * 功能:删除问题
     * param cid 问题id
     * */
    @RequestMapping("/api/problem/delete")
    @ResponseBody
    public ResultModel deleteCommonProblem(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel.put("statust_ime",new Date());
            SRModel.put("status_flag","0");
            commonProblemService.deleteCommonProblem(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }
}
